#!/usr/bin/env python
# -*- coding: utf-8 -*-

import store

def update_items_tables():
    db = store.ItemsDB('items_index.db')

    items1 = db.get_items1()
    print 'Processing %s items ...' % (len(items1), )
    
    k = 0
    for it1 in items1:
        if k % 100 == 0:
            print k
            db.commit()

        n1 = db.get_item_users(it1)
        
        items2 = db.get_half_shadow_item(it1)
        for it2 in items2:
            n2 = db.get_item_users(it2)
            db.update_items(n1*n2, it1, it2)
        
        k += 1
    
    db.commit()
    db.close()
    
update_items_tables()